package com.tutu.config;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.core.TopicExchange;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class ExchangeQueueConfig {

    @Bean
    public TopicExchange dataExchange() {
        return new TopicExchange("dataExchange", true, false); // 持久化，不自动删除
    }

    @Bean
    public TopicExchange msgExchange() {
        return new TopicExchange("msgExchange", true, false);
    }

    @Bean
    public Queue webAppDataQueue() {
        return new Queue("webAppDataQueue", true); // 持久化队列
    }

    @Bean
    public Queue webAppMsgQueue() {
        return new Queue("webAppMsgQueue", true);
    }

    @Bean
    public Binding dataBinding() {
        return BindingBuilder.bind(webAppDataQueue()).to(dataExchange()).with("#"); // 绑定所有路由键
    }

    @Bean
    public Binding msgBinding() {
        return BindingBuilder.bind(webAppMsgQueue()).to(msgExchange()).with("msg.*"); // 绑定msg开头的路由键
    }
}